package com.bc.bczbweb.controller;

import com.bc.commoncore.util.StringUtils;
import com.bc.commonentity.common.JsonResult;
import com.bc.bcapi.service.T_Activity_detailService;
import com.bc.bcmodel.domain.T_Activity_detailModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.math.BigInteger;

import org.springframework.web.bind.annotation.RequestMethod;
import com.bc.bccore.util.PageHelper;
import com.github.pagehelper.PageInfo;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("t_activity_detail")
public class T_Activity_detailController extends BaseController {
    @Autowired
    T_Activity_detailService t_Activity_detailService;

    @RequestMapping("list")
    public ModelAndView list(HttpServletRequest request) {
        ModelAndView view = super.baseView("列表", "t_activity_detail/list");
        view.addObject("acitvity_id", request.getParameter("acitvity_id"));
        view.addObject("language_data", request.getParameter("language_data"));
        return view;
    }

    @RequestMapping(value = "listdo", method = RequestMethod.POST)
    public ModelAndView listdo(T_Activity_detailModel req) {
        req.setPage_size(100);
        ModelAndView view = super.baseViewAjax("列表", "t_activity_detail/listdo");
        PageInfo<T_Activity_detailModel> pageInfo = t_Activity_detailService.getList(req);
        view.addObject("data", pageInfo.getList());
        view.addObject("page", PageHelper.GetAjaxHtml(pageInfo, "javascript:loadpage(##);"));
        view.addObject("acitvity_id", req.getAcitvity_id());
        return view;
    }

    @RequestMapping("add")
    public ModelAndView add(T_Activity_detailModel req) {
        String title = "添加";
        ModelAndView view = super.baseView(title, "t_activity_detail/add");
        T_Activity_detailModel data = null;
        if (req.getId().intValue() > 0) {
            title = "编辑";
            T_Activity_detailModel model = new T_Activity_detailModel();
            model.setId(req.getId());
            data = t_Activity_detailService.findByNamedParam(model);
        }
        if (data == null) {
            data = new T_Activity_detailModel();
            data.setAcitvity_id(req.getAcitvity_id());
            data.setLanguage_data(req.getLanguage_data());
            data.setId(new BigInteger("0"));
        }
        view.addObject("data", data);
        view.addObject("title", title);
        return view;
    }
}